#include<bits/stdc++.h>
#define int long long
#define double long double
#define rep(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define per(i,r,l) for(int i=(r),i##end=(l);i>=i##end;--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int maxn=5e3+10,maxm=1e6+10,mod=998244353,inf=1e18;
inline int ksm(int x,int k,int mod=mod){
    int ans=1;
    for(;k;k>>1,x=x*x%mod) if(k&1) ans=ans*x%mod;
    return ans;
}

int subid,T,n,k,m=5e3,a[maxn],b[maxn],vl[maxn],f[maxn][maxn];
inline signed subsolve(){
    cin>>n>>k,a[0]=m;
    rep(i,1,n-1) cin>>a[i];
    rep(i,1,k) cin>>b[i],b[i]+=b[i-1];
    rep(i,1,n) vl[i]=b[min(i,k)]-b[max(1ll,k-n+i)-1];
    rep(i,1,n){
        rep(j,0,a[i-1]) f[i][j]=f[i-1][a[i-1]-j]+j*vl[i];
        rep(j,1,m) f[i][j]=max(f[i][j],f[i][j-1]);
        // rep(j,1,20) cout<<f[i][j]-f[i][j-1]<<" \n"[j==jend];
    }
    cout<<f[n][m]<<'\n';
    return 0;
}

signed main(){
    freopen("festival.in","r",stdin),freopen("festival.out","w",stdout);
    ios::sync_with_stdio,cin.tie(0),cout.tie(0);
    cin>>subid>>T;
    rep(o,1,T) subsolve();
    return 0;
}/*
0 2
4 2
5 4 2
2 1
7 4
4 8 6 7 8 3
3 5 1 2

*/